package com.marc.eden;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.CompoundButton;
import android.widget.SeekBar;
import android.widget.Spinner;
import android.widget.Switch;
import android.widget.TextView;

public class OptionActivity extends AppCompatActivity implements SeekBar.OnSeekBarChangeListener,
        Switch.OnCheckedChangeListener {

    private Switch switch_nr;
    private TextView textView_nr;
    private SeekBar seekBar_minFaceSize;
    private TextView textView_minFaceSize;
    private SeekBar seekBar_interval;
    private TextView textView_interval;
//    private Spinner spinner_resolution;

    private boolean is106Points = false;
    private int min_face_size = 33;
    private int detection_interval = 1;
//    private String resolution = "1920*1080";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_option);

        init();
        load();
    }

    private void init() {
        switch_nr = (Switch) findViewById(R.id.switch_nr);
        textView_nr = (TextView) findViewById(R.id.textView_nr_right);
        seekBar_minFaceSize = (SeekBar) findViewById(R.id.seekBar_minFaceSize);
        textView_minFaceSize = (TextView) findViewById(R.id.textView_minFaceSize_right);
        seekBar_interval = (SeekBar) findViewById(R.id.seekBar_interval);
        textView_interval = (TextView) findViewById(R.id.textView_interval_right);
//        spinner_resolution = (Spinner) findViewById(R.id.spinner_resolution);

        switch_nr.setOnCheckedChangeListener(this);
        seekBar_minFaceSize.setOnSeekBarChangeListener(this);
        seekBar_interval.setOnSeekBarChangeListener(this);
    }

    private void load() {
        is106Points = switch_nr.isChecked();
        min_face_size = seekBar_minFaceSize.getProgress();
//        switch (spinner_resolution.getSelectedItemPosition()) {
//            case 0:
//                resolution = "1920*1080";
//                break;
//            case 1:
//                resolution = "1280*720";
//                break;;
//            case 2:
//                resolution = "800*600";
//                break;
//            default:
//                resolution = "640*480";
//                break;
//        }
        detection_interval = seekBar_interval.getProgress();
    }

    @Override
    protected void onDestroy()
    {
        super.onDestroy();

        load();
        Intent intent = new Intent(OptionActivity.this, ScannerActivity.class);
        intent.putExtra("is106Points",is106Points)
                .putExtra("min_face_size",min_face_size)
//                .putExtra("resolution",resolution)
                .putExtra("detection_interval",detection_interval);
    }

    @Override
    public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
        if (is106Points) {
            textView_nr.setText("106");
        } else {
            textView_nr.setText("81");
        }
    }

    @Override
    public void onStopTrackingTouch(SeekBar seekBar) {}

    @Override
    public void onStartTrackingTouch(SeekBar seekBar) {}

    @Override
    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
        switch(seekBar.getId()) {
            case R.id.seekBar_minFaceSize:{
                int minFaceSize = min_face_size;
                textView_minFaceSize.setText(minFaceSize);
                break;
            }
            case R.id.seekBar_interval: {
                int detectionInterval = detection_interval;
                textView_interval.setText(detectionInterval);
                break;
            }
            default:
                break;
        }
    }

}
